package com.example.demo.service.Impl;

import com.example.demo.entity.ChineseIndex;
import com.example.demo.mapper.ChineseIndexMapper;
import com.example.demo.service.IChineseIndexService;
import com.example.demo.vo.ChineseIndexVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChineseIndexServiceImpl implements IChineseIndexService {

    @Autowired
    private ChineseIndexMapper mapper;

    @Override
    public boolean insertChineseIndex(ChineseIndex chineseIndex) {
        int row = mapper.insertChineseIndex(chineseIndex);
        return row>0;
    }

    @Override
    public boolean deleteChineseIndex(String id) {
        return mapper.deleteChineseIndex(id);
    }

    @Override
    public boolean updateChineseIndex(ChineseIndex chineseIndex) {
        int row = mapper.updateChineseIndex(chineseIndex);
        return row>0;
    }

    @Override
    public List<ChineseIndexVo> selectChineseIndex(Integer pageNum, Integer pageSize) { // 返回实体类列表
        if (pageNum == null || pageSize == null) {
            throw new IllegalArgumentException("分页参数不能为空");
        }
        int realPageNum = (pageNum - 1) * pageSize; // 计算偏移量
        return mapper.selectChineseIndexList(realPageNum, pageSize); // Mapper 接收 offset 和 pageSize
    }
}
